﻿<AspNetMembershipManager:EditDialogWindow x:Class="AspNetMembershipManager.User.UserDetailsWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
		xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
		xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:vm="clr-namespace:AspNetMembershipManager.User"
        xmlns:AspNetMembershipManager="clr-namespace:AspNetMembershipManager"
        FocusManager.FocusedElement="{Binding ElementName=txtUserName}"
		d:DataContext="{d:DesignInstance vm:UserDetailsModel}" mc:Ignorable="d"
        Title="User Details" Height="425" Width="967">
	<Window.CommandBindings>
		<CommandBinding Command="Save" CanExecute="Ok_CanExecute" Executed="Ok_Executed" />
		<CommandBinding Command="vm:UserDetailsWindowCommands.ResetPassword" CanExecute="CanResetPassword" Executed="ResetPassword" />
	</Window.CommandBindings>
    <Grid>
		<Grid.Resources>
			<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
		</Grid.Resources>
		<DockPanel Height="315" VerticalAlignment="Top">
			<TabControl Margin="12">
				<TabItem Header="User details">
					<Grid>
						<Grid.ColumnDefinitions>
							<ColumnDefinition Width="550" />
							<ColumnDefinition Width="*" />
						</Grid.ColumnDefinitions>
						<Grid.RowDefinitions>
							<RowDefinition Height="auto" />
							<RowDefinition Height="auto" />
							<RowDefinition Height="*" />
						</Grid.RowDefinitions>
						<GroupBox Header="Details" HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="10,0,10,0" Grid.Row="0" Grid.Column="0">
							<Grid>
								<Grid.ColumnDefinitions>
									<ColumnDefinition Width="Auto" />
									<ColumnDefinition Width="*" />
								</Grid.ColumnDefinitions>
								<Grid.RowDefinitions>
									<RowDefinition Height="auto" />
									<RowDefinition Height="auto" />
								</Grid.RowDefinitions>
								<Label Content="Username:" Grid.Column="0" Grid.Row="0" />
								<Label Content="Email address:" Grid.Column="0" Grid.Row="1" />
								<TextBox Text="{Binding UserName, Mode=OneWay}" IsReadOnly="True" Name="txtUserName" Grid.Column="1" Grid.Row="0" />
								<TextBox Grid.Column="1" Grid.Row="1"
									 Validation.Error="Validation_Error"
									 Text="{Binding UpdateSourceTrigger=PropertyChanged, Path=EmailAddress, ValidatesOnDataErrors=true, NotifyOnValidationError=true}" />
							</Grid>
						</GroupBox>
						<GroupBox Header="Password question" IsEnabled="{Binding RequiresQuestionAndAnswer}" HorizontalAlignment="Stretch" Margin="10,0,10,0" VerticalAlignment="Stretch" Grid.Row="1" Grid.Column="0">
							<TextBox Text="{Binding PasswordQuestion, Mode=OneWay}" IsReadOnly="True" />
						</GroupBox>
						<GroupBox Header="Activity" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="11,0,9,0" Grid.Column="1" Grid.RowSpan="2">
							<Grid>
								<Grid.ColumnDefinitions>
									<ColumnDefinition Width="Auto" />
									<ColumnDefinition Width="*" />
								</Grid.ColumnDefinitions>
								<Grid.RowDefinitions>
									<RowDefinition Height="auto" />
									<RowDefinition Height="auto" />
									<RowDefinition Height="auto" />
									<RowDefinition Height="auto" />
									<RowDefinition Height="auto" />
								</Grid.RowDefinitions>
								<Label Content="Creation:" Grid.Column="0" Grid.Row="0" />
								<Label Content="Last activity:" Grid.Column="0" Grid.Row="1" />
								<Label Content="Last lockout:" Grid.Column="0" Grid.Row="2" />
								<Label Content="Last login:" Grid.Column="0" Grid.Row="3" />
								<Label Content="Last password change:" Grid.Column="0" Grid.Row="4" />
								<TextBox Text="{Binding CreationDate, Mode=OneWay, StringFormat=R}" IsReadOnly="True" Grid.Column="1" Grid.Row="0"  Style="{StaticResource noValidationTextBox}" />
								<TextBox Text="{Binding LastActivityDate, Mode=OneWay, StringFormat=R}" IsReadOnly="True" Grid.Column="1" Grid.Row="1" Style="{StaticResource noValidationTextBox}" />
								<TextBox Text="{Binding LastLockoutDate, Mode=OneWay, StringFormat=R}" IsReadOnly="True" Grid.Column="1" Grid.Row="2" Style="{StaticResource noValidationTextBox}" />
								<TextBox Text="{Binding LastLoginDate, Mode=OneWay, StringFormat=R}" IsReadOnly="True" Grid.Column="1" Grid.Row="3" Style="{StaticResource noValidationTextBox}" />
								<TextBox Text="{Binding LastPasswordChangeDate, Mode=OneWay, StringFormat=R}" IsReadOnly="True" Grid.Column="1" Grid.Row="4" Style="{StaticResource noValidationTextBox}" />
							</Grid>
						</GroupBox>
						<GroupBox Header="Comment" HorizontalAlignment="Stretch" Margin="10,0,10,0" VerticalAlignment="Stretch" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2">
							<TextBox Text="{Binding Comment}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" TextWrapping="Wrap" AcceptsReturn="True" Style="{StaticResource noValidationTextBox}" />
						</GroupBox>
					</Grid>
				</TabItem>
				<TabItem Header="User profile" Visibility="{Binding ProfilesEnabled, Converter={StaticResource BooleanToVisibilityConverter}}">
					<Grid>
						<DataGrid ItemsSource="{Binding Profile}" Margin="6" IsReadOnly="True">
							<DataGrid.Columns>
								<DataGridTextColumn Header="Property name" Binding="{Binding PropertyName}" IsReadOnly="True" />
								<DataGridTextColumn Header="Property type" Binding="{Binding PropertyType}" IsReadOnly="True" />
								<DataGridTemplateColumn Header="Property value">
									<DataGridTemplateColumn.CellTemplateSelector>
										<vm:ProfilePropertyTemplateSelector>
											<vm:ProfilePropertyTemplateSelector.BooleanTemplate>
												<DataTemplate>
													<CheckBox IsChecked="{Binding PropertyValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
												</DataTemplate>
											</vm:ProfilePropertyTemplateSelector.BooleanTemplate>
											<vm:ProfilePropertyTemplateSelector.StringTemplate>
												<DataTemplate>
													<TextBox HorizontalAlignment="Stretch" Text="{Binding PropertyValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
												</DataTemplate>
											</vm:ProfilePropertyTemplateSelector.StringTemplate>
											<vm:ProfilePropertyTemplateSelector.NumberTemplate>
												<DataTemplate>
													<TextBox HorizontalAlignment="Stretch" Text="{Binding PropertyValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
												</DataTemplate>
											</vm:ProfilePropertyTemplateSelector.NumberTemplate>
											<vm:ProfilePropertyTemplateSelector.DateTimeTemplate>
												<DataTemplate>
													<DatePicker SelectedDate="{Binding PropertyValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"  />
												</DataTemplate>
											</vm:ProfilePropertyTemplateSelector.DateTimeTemplate>
											<vm:ProfilePropertyTemplateSelector.EnumerableTemplate>
												<DataTemplate>
													<Button Content="..." Click="CollectionPropertyEdit" />
												</DataTemplate>
											</vm:ProfilePropertyTemplateSelector.EnumerableTemplate>
											<vm:ProfilePropertyTemplateSelector.ObjectTemplate>
												<DataTemplate>
													<Button Content="..." Click="CustomProfilePropertyEdit" />
												</DataTemplate>
											</vm:ProfilePropertyTemplateSelector.ObjectTemplate>
											<vm:ProfilePropertyTemplateSelector.NotSupportedTemplate>
												<DataTemplate>
													<Label>&lt;Data type not supported&gt;</Label>
												</DataTemplate>
											</vm:ProfilePropertyTemplateSelector.NotSupportedTemplate>
										</vm:ProfilePropertyTemplateSelector>
									</DataGridTemplateColumn.CellTemplateSelector>
								</DataGridTemplateColumn>
							</DataGrid.Columns>
						</DataGrid>
					</Grid>
				</TabItem>
				<TabItem Header="Roles" Visibility="{Binding RolesEnabled, Converter={StaticResource BooleanToVisibilityConverter}}">
					<Grid>
						<ListBox ItemsSource="{Binding Roles, Mode=OneWay}" IsSynchronizedWithCurrentItem="True" FontSize="12" Height="Auto" VerticalAlignment="Stretch" SelectedIndex="0">
							<ListBox.ItemTemplate>
								<DataTemplate>
									<CheckBox Name="CheckBoxZone" Content="{Binding RoleName}" Tag="{Binding RoleName}"	IsChecked="{Binding IsMember}" Margin="0,5,0,0"/>
								</DataTemplate>
							</ListBox.ItemTemplate>
						</ListBox>
					</Grid>
				</TabItem>
			</TabControl>
		</DockPanel>
		<GroupBox Header="Actions" VerticalAlignment="Bottom" Margin="10">
			<Grid>
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition Width="*" />
				</Grid.ColumnDefinitions>
				<StackPanel Orientation="Horizontal" Grid.Column="0">
					<StackPanel.Resources>
						<Style TargetType="{x:Type Button}">
							<Setter Property="Margin" Value="0,0,10,0" />
							<Setter Property="Padding" Value="10,0,10,0" />
						</Style>
					</StackPanel.Resources>
					<Button Content="Reset password" Command="vm:UserDetailsWindowCommands.ResetPassword" />
					<Button Content="Unlock account"
							CommandParameter="{Binding}"
					        Command="{Binding UnlockUserCommand}" />
					<Button Content="Activate account"
							Width="130"
							Visibility="{Binding IsAccountDectivated, Converter={StaticResource BooleanToVisibilityConverter}}"
							CommandParameter="{Binding}"
							Command="{Binding ActivateUserCommand}" />
					<Button Content="Deactivate account"
							Width="130"
							Visibility="{Binding IsAccountActivated, Converter={StaticResource BooleanToVisibilityConverter}}"
							CommandParameter="{Binding}"
							Command="{Binding DeactivateUserCommand}" />
				</StackPanel>
				<StackPanel Orientation="Horizontal" FlowDirection="RightToLeft" Grid.Column="1">
					<StackPanel.Resources>
						<Style TargetType="{x:Type Button}">
							<Setter Property="Margin" Value="10,0,0,0"/>
						</Style>
					</StackPanel.Resources>
					<Button Content="Save" IsDefault="True" Width="75" Command="Save" />
					<Button Content="Cancel" IsCancel="True" Width="75" />
				</StackPanel>
			</Grid>
		</GroupBox>
	</Grid>
</AspNetMembershipManager:EditDialogWindow>
